package com.tg.sieve_data.service.impl;

import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tg.sieve_data.entity.VisitRecord;
import com.tg.sieve_data.mapper.VisitRecordMapper;
import com.tg.sieve_data.po.TgGroupPO;
import com.tg.sieve_data.po.VisitRecordExportPO;
import com.tg.sieve_data.service.VisitRecordService;
import com.tg.sieve_data.vo.VisitRecordVO;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

@Service
public class VisitRecordServiceImpl extends ServiceImpl<VisitRecordMapper, VisitRecord> implements VisitRecordService {

    @Override
    public Page<VisitRecord> statistics(VisitRecordVO visitRecordVO, Integer pageNum, Integer pageSize) {
        Page<VisitRecord> page = new Page<>(pageNum, pageSize);
        List<VisitRecord> records = this.baseMapper.statistics(page, visitRecordVO);
        if (CollUtil.isNotEmpty(records)) {
            records.stream().filter(record -> "获取不到IP".equals(record.getCountryName())).forEach(record -> record.setCountryName("未知"));
        }
        page.setRecords(records);
        return page;
    }

    @Override
    public List<VisitRecordExportPO> selectExportDatas(VisitRecordVO visitRecordVO) {
        return this.baseMapper.selectExportDatas(visitRecordVO);
    }
}
